Show dialog titles
authorMatthias Clasen <mclasen@redhat.com>
Fri, 14 Mar 2014 10:28:49 +0000 (06:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 14 Mar 2014 10:28:49 +0000 (06:28 -0400)
We want to present a clean, rounded top when there is nothing
else to show, but many dialogs in applications rely on showing
information in their title, so add a label and show the title
when it is not empty.

gtk/gtkdialog.c

index 37d9bf0bce07d5408d93de18db94b9d3895a5a30..3b54c46b004d80042de45f5ad010b3ac27bd628b 100644 (file)
@@ -271,6 +271,18 @@ add_cb (GtkContainer *container,
   gtk_widget_show (GTK_WIDGET (container));
 }
 
+static void
+update_title (GObject    *dialog,
+              GParamSpec *pspec,
+              GtkWidget  *label)
+{
+  const gchar *title;
+
+  title = gtk_window_get_title (GTK_WINDOW (dialog));
+  gtk_label_set_label (GTK_LABEL (label), title);
+  gtk_widget_set_visible (label, title && title[0]);
+}
+
 static void
 apply_use_header_bar (GtkDialog *dialog)
 {
@@ -284,9 +296,15 @@ apply_use_header_bar (GtkDialog *dialog)
 
       if (gtk_window_get_type_hint (GTK_WINDOW (dialog)) == GDK_WINDOW_TYPE_HINT_DIALOG)
         {
+          GtkWidget *label;
+
           box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
           gtk_widget_show (box);
           gtk_widget_set_size_request (box, -1, 16);
+          label = gtk_label_new ("");
+          gtk_style_context_add_class (gtk_widget_get_style_context (label), "title");
+          gtk_box_set_center_widget (GTK_BOX (box), label);
+          g_signal_connect (dialog, "notify::title", G_CALLBACK (update_title), label);
         }
 
       gtk_window_set_titlebar (GTK_WINDOW (dialog), box);